﻿namespace Smart.Utils.UI.BarcodeLib
{
    using System;

    internal class ISBN : BarcodeCommon, IBarcode
    {
        public ISBN(string input)
        {
            base.Raw_Data = input;
        }

        private string Encode_ISBN_Bookland()
        {
            if (!BarcodeEdit.CheckNumericOnly(base.Raw_Data))
            {
                throw new Exception("EBOOKLANDISBN-1: Numeric Data Only");
            }
            string str = "UNKNOWN";
            if ((base.Raw_Data.Length == 10) || (base.Raw_Data.Length == 9))
            {
                if (base.Raw_Data.Length == 10)
                {
                    base.Raw_Data = base.Raw_Data.Remove(9, 1);
                }
                base.Raw_Data = "978" + base.Raw_Data;
                str = "ISBN";
            }
            else if ((base.Raw_Data.Length == 12) && base.Raw_Data.StartsWith("978"))
            {
                str = "BOOKLAND-NOCHECKDIGIT";
            }
            else if ((base.Raw_Data.Length == 13) && base.Raw_Data.StartsWith("978"))
            {
                str = "BOOKLAND-CHECKDIGIT";
                base.Raw_Data = base.Raw_Data.Remove(12, 1);
            }
            if (str == "UNKNOWN")
            {
                throw new Exception("EBOOKLANDISBN-2: Invalid input.  Must start with 978 and be length must be 9, 10, 12, 13 characters.");
            }
            EAN13 ean = new EAN13(base.Raw_Data);
            return ean.Encoded_Value;
        }

        public string Encoded_Value
        {
            get
            {
                return this.Encode_ISBN_Bookland();
            }
        }
    }
}

